package com.tansun.easycare.rule.common.rulebasebean;

import org.apache.commons.lang3.StringUtils;

/**
 * 规则变量的声明项 生成Drl文件时默认会有map(...)包括
 *
 * @author WanYe
 */
public class Fact implements Comparable<Fact> {
	
	public static int TYPE_ENTRY = 1;
	public static int TYPE_RULE = 0;
    /**
     * 顺序
     */
    private Integer sort = 0;
    /**
     * 临时内容
     */
    private String content = "";

    /**
     * 行与行之间的逻辑
     */
    private LineLogic lineLogic;
    
    /**
     * 类型，type = rule 规则，type=entry 条目
     */
    private int type = TYPE_RULE;
    /**
     * 实现方法为提供drools的语句
     */
    //public abstract String getRuleContent();
    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Override
    public int compareTo(Fact arg0) {
        return this.getSort().compareTo(arg0.getSort());
    }

	public LineLogic getLineLogic() {
		return lineLogic;
	}

	public void setLineLogic(LineLogic lineLogic) {
		this.lineLogic = lineLogic;
	}
	
	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public String getLinePrefix() {
		if(lineLogic==null) {
			return "";
		}else {
			String left = lineLogic.getLeft();
			if(StringUtils.isNotEmpty(left)) {
				return left;
			}else {
				return "";
			}
		}
	}

	public String getLineSuffix() {
		if(lineLogic==null) {
			return "";
		}else {
			String suffix = "";
			String right = lineLogic.getRight();
			if(StringUtils.isNotEmpty(right)) {
				suffix = right;
			}
			String logic = lineLogic.getLogic();
			if("and".equals(logic)) {
				suffix += " && ";
			}else if("or".equals(logic)) {
				suffix += " || ";
			}
			return suffix;
		}
	}
    
	public String getLastLineSuffix() {
		if(lineLogic==null) {
			return "";
		}else {
			String suffix = "";
			String right = lineLogic.getRight();
			if(StringUtils.isNotEmpty(right)) {
				suffix = right;
			}
			return suffix;
		}
	}
}
